﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Timers;
using DLL.Entities;


namespace COM
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        ReadXML xRead = new ReadXML();

        private void Form1_Load(object sender, EventArgs e)
        {
            
            COM_Config modver = new COM_Config();
            modver = xRead.ReadCOMConfig();
                   
            txtComModel.Text = Convert.ToString(modver.Model);
            txtComVersion.Text = Convert.ToString(modver.Version);
        }

        string cwd = System.IO.Directory.GetCurrentDirectory();

        private void tRead_Tick(object sender, EventArgs e)
        {
            if (File.Exists("../../../DLL/XML/RAD_Update.xml"))
            {
                Targets bogie = new Targets();
                bogie = xRead.ReadRADEvent("../../../DLL/XML/RAD_Update.xml");
                       
                AltitudeTextBox.Text = bogie.Altitude;
                speedType.Text = bogie.Speed;
                commDistance.Text = bogie.Distance;
                commDirection.Text = bogie.Direction;
                bogieSize.Text = bogie.Size;
                bogieType.Text = bogie.TargetName;

                File.Delete("../../../DLL/XML/RAD_Update.xml");

                statOfRad.Text = "Online";
            }
            else
            {
                statOfRad.Text = "Offline";
                bogieType.Text = "N/A";
                AltitudeTextBox.Text = "N/A";
                speedType.Text = "N/A";
                commDistance.Text = "N/A";
                commDirection.Text = "N/A";
                bogieSize.Text = "N/A";
            }


            if (File.Exists("../../../DLL/XML/Mis_Status.xml"))
            {

                MISStatus currentMis = new MISStatus();
                currentMis = xRead.ReadMISStatus("../../../DLL/XML/Mis_Status.xml");


                miss_Remain.Text = Convert.ToString(currentMis.MissileCount);
                typeOfMiss.Text = currentMis.MissileType;
                statOfMiss.Text = currentMis.CurrentStatus;

                File.Delete("../../../DLL/XML/Mis_Status.xml");
            }
            else
            {
                miss_Remain.Text = "0";
                typeOfMiss.Text = "N/A";
                statOfMiss.Text = "Offline";
            }
                            
        }

        #region
        private void txtComModel_TextChanged(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void txtComVersion_TextChanged(object sender, EventArgs e)
        {

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void txtMisRem_TextChanged(object sender, EventArgs e)
        {

        }

        private void label13_Click(object sender, EventArgs e)
        {

        }

        private void txtAltitude_TextChanged(object sender, EventArgs e)
        {

        }
        #endregion
    }
}